import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes} from '@/api/config'
import qs from 'qs'
export interface Login{
  phone:string
  password:string
}


//用户信息数据
export interface UserInfor{
  id:string,
  phone:string, // 联系电话
  loginName:string, // 登录账号
  userName:string, //用户姓名
  roleName:string, // 角色名称
  jobName:string, // 岗位名称
  menuJson:string, // 角色菜单json
}

//登录
export const login = (data:Login):AxiosPromise<DataRes<string>> => {
  return request({
    url:'/api/login',
    method:'post',
    data:data
  })
}

//获取公钥
export const getPublicKey = ():AxiosPromise<DataRes<string>> => {
  return request({
    url:'/api/auth/publicKey',
    method:'get'
  })
}

export interface GetDict{
  dictCodes:string
}

export interface DicItem{
  dictItemCode:string
  dictItemName:string
}
export interface DicData{
  items:Array<DicItem>
}
//获取字典
export const getDicData = (params:GetDict):AxiosPromise<DataRes<Array<DicData>>> => {
  return request({
    url:'/api/dict/get/items',
    method:'get',
    params
  })
}

//退出登录
export const outLogin = ():AxiosPromise<DataRes<null>> => {
  return request({
    url:'/api/auth/logout',
    method:'post'
  })
}

//修改密码
export const changePass = (data:{oldPass:string, newPass:string}):AxiosPromise<DataRes<null>> => {
  return request({
    url:'/api/user/changePwd',
    method:'post',
    data
  })
}

//获取用户信息
export const getUserInfoByUser = ():AxiosPromise<DataRes<UserInfor>> => {
  return request({
    url:'/api/user/authority',
    method:'get'
  })
}

//密码强度
export type PasswordLvType=1|2|3